/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.alipay.study.web.header;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alipay.study.common.util.log.LogUtil;

/**
 * 
 * @author wb-qlj205528
 * @version $Id: ContentSecurityPolicy.java, v 0.1 2016年11月14日 下午4:21:05 wb-qlj205528 Exp $
 */
@RestController
@RequestMapping(value = "/contentsecuritypolicy", method = RequestMethod.POST)
public class ContentSecurityPolicy {

    private static Logger LOGGER = Logger.getLogger(ContentSecurityPolicy.class);

    /**
     * 
     * 
     * @param str
     */
    @RequestMapping("/reporturl")
    @ApiOperation(value = "Content Security Policy report Url", notes = "Content Security Policy report Url")
    @ApiImplicitParam(name = "request", value = "HttpServletRequest 请求对象", required = true, dataType = "javax.servlet.http.HttpServletRequest")
    public void reportUrl(HttpServletRequest request) {
        try {
            BufferedReader reader = request.getReader();

            StringBuilder strb = new StringBuilder();

            char[] buffer = new char[1024];

            int len;
            while ((len = reader.read(buffer)) != -1) {
                strb.append(buffer, 0, len);
            }
            LogUtil.warn(LOGGER, strb);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
